/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 spell_set.h

	$Header: /heroes4/spell_set.h $

	$NoKeywords: $

 ************************************************************************/

#include "precompiled.h"
#include "spell_set.h"

#include "bitset_io.h"
#include "elements_of.h"
#include "streambuf_operators.h"

enum t_version_0_spells
{
	k_version_0_acid,
	k_version_0_aging,
	k_version_0_animate_dead,
	k_version_0_anti_magic,
	k_version_0_armageddon,
	k_version_0_banish,
	k_version_0_berserk,
	k_version_0_bind_flyer,
	k_version_0_bind_wound,
	k_version_0_binding,
	k_version_0_bless,
	k_version_0_blind,
	k_version_0_bloodfrenzy,
	k_version_0_bloodlust,
	k_version_0_burning_hands,
	k_version_0_cancellation,
	k_version_0_celestial_armor,
	k_version_0_chain_lightning,
	k_version_0_clone,
	k_version_0_cloud_of_confusion,
	k_version_0_cold_resistance,
	k_version_0_confusion,
	k_version_0_cowardice,
	k_version_0_curse,
	k_version_0_death_call,
	k_version_0_despair,
	k_version_0_disintegrate,
	k_version_0_dispel,
	k_version_0_displacement,
	k_version_0_divine_aura,
	k_version_0_divine_intervention,
	k_version_0_divine_protection,
	k_version_0_divine_retribution,
	k_version_0_dragon_strength,
	k_version_0_evil_hour,
	k_version_0_exorcism,
	k_version_0_fear,
	k_version_0_fire_bolt,
	k_version_0_fire_resistance,
	k_version_0_fire_ring,
	k_version_0_fire_shield,
	k_version_0_fireball,
	k_version_0_firebreathing,
	k_version_0_first_strike,
	k_version_0_flight,
	k_version_0_forgetfulness,
	k_version_0_fortune,
	k_version_0_freeze,
	k_version_0_gas,
	k_version_0_giant_strength,
	k_version_0_greater_forgetfulness,
	k_version_0_guardian_angel,
	k_version_0_hand_of_death,
	k_version_0_haste,
	k_version_0_heal,
	k_version_0_health_boost,
	k_version_0_holy_armor,
	k_version_0_holy_retribution,
	k_version_0_holy_water,
	k_version_0_holy_word,
	k_version_0_hypnotize,
	k_version_0_ice_bolt,
	k_version_0_illusionary_ally,
	k_version_0_implosion,
	k_version_0_inferno,
	k_version_0_kreegan_fire,
	k_version_0_life_drain,
	k_version_0_lightning,
	k_version_0_luck_boost,
	k_version_0_magic_arrow,
	k_version_0_magic_fist,
	k_version_0_magic_leech,
	k_version_0_magic_mirror,
	k_version_0_magic_resistance,
	k_version_0_mana,
	k_version_0_mana_flare,
	k_version_0_mana_leech,
	k_version_0_martyr,
	k_version_0_mass_bless,
	k_version_0_mass_cancellation,
	k_version_0_mass_curse,
	k_version_0_mass_dispel,
	k_version_0_mass_exorcism,
	k_version_0_mass_first_strike,
	k_version_0_mass_fortune,
	k_version_0_mass_haste,
	k_version_0_mass_healing,
	k_version_0_mass_misfortune,
	k_version_0_mass_precision,
	k_version_0_mass_protection_from_chaos,
	k_version_0_mass_protection_from_death,
	k_version_0_mass_protection_from_nature,
	k_version_0_mass_protection_from_order,
	k_version_0_mass_slayer,
	k_version_0_mass_slow,
	k_version_0_mass_snake_strike,
	k_version_0_mass_sorrow,
	k_version_0_mass_spiritual_fervor,
	k_version_0_mass_weakness,
	k_version_0_mire,
	k_version_0_misfortune,
	k_version_0_morale_boost,
	k_version_0_nature_haste,
	k_version_0_order_slow,
	k_version_0_pain_mirror,
	k_version_0_panic,
	k_version_0_pathfinding,
	k_version_0_physical_protection,
	k_version_0_plague,
	k_version_0_poison,
	k_version_0_poison_attack,
	k_version_0_power_drain,
	k_version_0_prayer,
	k_version_0_precision,
	k_version_0_precognition,
	k_version_0_protection_from_chaos,
	k_version_0_protection_from_death,
	k_version_0_protection_from_life,
	k_version_0_protection_from_nature,
	k_version_0_protection_from_order,
	k_version_0_quickness,
	k_version_0_quicksand,
	k_version_0_raise_ghost,
	k_version_0_raise_skeletons,
	k_version_0_raise_vampires,
	k_version_0_ranged_protection,
	k_version_0_ray_of_suffering,
	k_version_0_rebirth,
	k_version_0_reflexes,
	k_version_0_regeneration,
	k_version_0_endurance,
	k_version_0_resurrection,
	k_version_0_rock_growth,
	k_version_0_sacred_ground,
	k_version_0_sacrifice,
	k_version_0_sanctuary,
	k_version_0_short_hypnotism,
	k_version_0_simple_healing,
	k_version_0_slayer,
	k_version_0_slow,
	k_version_0_smoke,
	k_version_0_snake_strike,
	k_version_0_song_of_peace,
	k_version_0_sorrow,
	k_version_0_speed,
	k_version_0_spell_shackle,
	k_version_0_spiritual_fervor,
	k_version_0_steal_all_enchantments,
	k_version_0_steal_enchantment,
	k_version_0_stoneskin,
	k_version_0_stone_gaze,
	k_version_0_strength,
	k_version_0_stun,
	k_version_0_summon_elf,
	k_version_0_summon_white_tiger,
	k_version_0_summon_air_elemental,
	k_version_0_summon_boat,
	k_version_0_summon_cerberi,
	k_version_0_summon_demon,
	k_version_0_summon_venom_spawn,
	k_version_0_summon_devils,
	k_version_0_summon_earth_elemental,
	k_version_0_summon_faerie_dragon,
	k_version_0_summon_fire_elemental,
	k_version_0_summon_griffin,
	k_version_0_summon_ice_demon,
	k_version_0_summon_imps,
	k_version_0_summon_leprechaun,
	k_version_0_summon_mantis,
	k_version_0_summon_phoenix,
	k_version_0_summon_satyr,
	k_version_0_summon_sprite,
	k_version_0_summon_stinkbug,
	k_version_0_summon_unicorn,
	k_version_0_summon_water_elemental,
	k_version_0_summon_wolf,
	k_version_0_teleport,
	k_version_0_terrain_walk,
	k_version_0_terror,
	k_version_0_town_gate,
	k_version_0_vampiric_touch,
	k_version_0_visions,
	k_version_0_water_walk,
	k_version_0_weakness,

	k_version_0_count = k_version_0_weakness + 1,
};

static int k_version_0_index[][2] =
{
	{ k_version_0_acid,			k_spell_acid },
	{ k_version_0_aging,		k_spell_aging },
	{ k_version_0_animate_dead,	k_spell_animate_dead },
	{ k_version_0_anti_magic,	k_spell_anti_magic },
	{ k_version_0_armageddon,	k_spell_armageddon },
	{ k_version_0_banish,		k_spell_banish },
	{ k_version_0_berserk,		k_spell_berserk },
	{ k_version_0_bind_flyer,	k_spell_bind_flyer },
	{ k_version_0_bind_wound,	k_spell_bind_wound },
	{ k_version_0_binding,		k_spell_binding },
	{ k_version_0_bless,		k_spell_bless },
	{ k_version_0_blind,		k_spell_blind },
	{ k_version_0_bloodfrenzy,	k_spell_bloodfrenzy },
	{ k_version_0_bloodlust,	k_spell_bloodlust },
	{ k_version_0_burning_hands,	k_spell_burning_hands },
	{ k_version_0_cancellation,		k_spell_cancellation },
	{ k_version_0_celestial_armor,	k_spell_celestial_armor },
	{ k_version_0_chain_lightning,	k_spell_chain_lightning },
	{ k_version_0_clone,			k_spell_clone },
	{ k_version_0_cloud_of_confusion,	k_spell_cloud_of_confusion },
	{ k_version_0_cold_resistance,		k_spell_cold_resistance },
	{ k_version_0_confusion,			k_spell_confusion },
	{ k_version_0_cowardice,			k_spell_cowardice },
	{ k_version_0_curse,				k_spell_curse },
	{ k_version_0_death_call,			k_spell_death_call },
	{ k_version_0_despair,				k_spell_despair },
	{ k_version_0_disintegrate,			k_spell_disintegrate },
	{ k_version_0_dispel,				k_spell_dispel },
	{ k_version_0_displacement,			k_spell_displacement },
	{ k_version_0_divine_aura,			k_spell_divine_aura },
	{ k_version_0_divine_intervention,	k_spell_divine_intervention },
	{ k_version_0_divine_protection,	k_spell_divine_protection },
	{ k_version_0_divine_retribution,	k_spell_divine_retribution },
	{ k_version_0_dragon_strength,		k_spell_dragon_strength },
	{ k_version_0_evil_hour,			k_spell_evil_hour },
	{ k_version_0_exorcism,				k_spell_exorcism },
	{ k_version_0_fear,					k_spell_fear },
	{ k_version_0_fire_bolt,			k_spell_fire_bolt },
	{ k_version_0_fire_resistance,		k_spell_fire_resistance },
	{ k_version_0_fire_ring,			k_spell_fire_ring },
	{ k_version_0_fire_shield,			k_spell_fire_shield },
	{ k_version_0_fireball,				k_spell_fireball },
	{ k_version_0_firebreathing,		k_spell_firebreathing },
	{ k_version_0_first_strike,			k_spell_first_strike },
	{ k_version_0_flight,				k_spell_flight },
	{ k_version_0_forgetfulness,		k_spell_forgetfulness },
	{ k_version_0_fortune,				k_spell_fortune },
	{ k_version_0_freeze,				k_spell_freezing_attack },
	{ k_version_0_gas,					k_spell_gas },
	{ k_version_0_giant_strength,		k_spell_giant_strength },
	{ k_version_0_greater_forgetfulness,	k_spell_greater_forgetfulness },
	{ k_version_0_guardian_angel,			k_spell_guardian_angel },
	{ k_version_0_hand_of_death,			k_spell_hand_of_death },
	{ k_version_0_haste,					k_spell_haste },
	{ k_version_0_heal,						k_spell_heal },
	{ k_version_0_health_boost,				k_spell_health_boost },
	{ k_version_0_holy_armor,				k_spell_holy_armor },
	{ k_version_0_holy_retribution,			k_spell_holy_retribution },
	{ k_version_0_holy_water,				k_spell_holy_water },
	{ k_version_0_holy_word,				k_spell_holy_word },
	{ k_version_0_hypnotize,				k_spell_hypnotize },
	{ k_version_0_ice_bolt,					k_spell_ice_bolt },
	{ k_version_0_illusionary_ally,			k_spell_illusionary_ally },
	{ k_version_0_implosion,				k_spell_implosion },
	{ k_version_0_inferno,					k_spell_inferno },
	{ k_version_0_kreegan_fire,				k_spell_kreegan_fire },
	{ k_version_0_life_drain,				k_spell_life_drain },
	{ k_version_0_lightning,				k_spell_lightning },
	{ k_version_0_luck_boost,				k_spell_luck_boost },
	{ k_version_0_magic_arrow,				k_spell_magic_arrow },
	{ k_version_0_magic_fist,				k_spell_magic_fist },
	{ k_version_0_magic_leech,				k_spell_magic_leech },
	{ k_version_0_magic_mirror,				k_spell_magic_mirror },
	{ k_version_0_magic_resistance,			k_spell_magic_resistance },
	{ k_version_0_mana,						k_spell_mana },
	{ k_version_0_mana_flare,				k_spell_mana_flare },
	{ k_version_0_mana_leech,				k_spell_mana_leech },
	{ k_version_0_martyr,					k_spell_martyr },
	{ k_version_0_mass_bless,				k_spell_mass_bless },
	{ k_version_0_mass_cancellation,		k_spell_mass_cancellation },
	{ k_version_0_mass_curse,				k_spell_mass_curse },
	{ k_version_0_mass_dispel,				k_spell_mass_dispel },
	{ k_version_0_mass_exorcism,			k_spell_mass_exorcism },
	{ k_version_0_mass_first_strike,		k_spell_mass_first_strike },
	{ k_version_0_mass_fortune,				k_spell_mass_fortune },
	{ k_version_0_mass_haste,				k_spell_mass_haste },
	{ k_version_0_mass_healing,				k_spell_mass_healing },
	{ k_version_0_mass_misfortune,			k_spell_mass_misfortune },
	{ k_version_0_mass_precision,			k_spell_mass_precision },
	{ k_version_0_mass_protection_from_chaos,	k_spell_mass_protection_from_chaos },
	{ k_version_0_mass_protection_from_death,	k_spell_mass_protection_from_death },
	{ k_version_0_mass_protection_from_nature,	k_spell_mass_protection_from_nature },
	{ k_version_0_mass_protection_from_order,	k_spell_mass_protection_from_order },
	{ k_version_0_mass_slayer,					k_spell_mass_slayer },
	{ k_version_0_mass_slow,					k_spell_mass_slow },
	{ k_version_0_mass_snake_strike,			k_spell_mass_snake_strike },
	{ k_version_0_mass_sorrow,					k_spell_mass_sorrow },
	{ k_version_0_mass_spiritual_fervor,		k_spell_mass_spiritual_fervor },
	{ k_version_0_mass_weakness,				k_spell_mass_weakness },
	{ k_version_0_mire,							k_spell_mire },
	{ k_version_0_misfortune,					k_spell_misfortune },
	{ k_version_0_morale_boost,					k_spell_morale_boost },
	{ k_version_0_nature_haste,					k_spell_nature_haste },
	{ k_version_0_order_slow,					k_spell_order_slow },
	{ k_version_0_pain_mirror,					k_spell_pain_mirror },
	{ k_version_0_panic,						k_spell_panic },
	{ k_version_0_pathfinding,					k_spell_pathfinding },
	{ k_version_0_physical_protection,			k_spell_blur },
	{ k_version_0_plague,						k_spell_plague },
	{ k_version_0_poison,						k_spell_poison },
	{ k_version_0_poison_attack,				k_spell_poison_attack },
	{ k_version_0_power_drain,					k_spell_power_drain },
	{ k_version_0_prayer,						k_spell_prayer },
	{ k_version_0_precision,					k_spell_precision },
	{ k_version_0_precognition,					k_spell_immortality },
	{ k_version_0_protection_from_chaos,		k_spell_protection_from_chaos },
	{ k_version_0_protection_from_death,		k_spell_protection_from_death },
	{ k_version_0_protection_from_life,			k_spell_protection_from_life },
	{ k_version_0_protection_from_nature,		k_spell_protection_from_nature },
	{ k_version_0_protection_from_order,		k_spell_protection_from_order },
	{ k_version_0_quickness,					k_spell_quickness },
	{ k_version_0_quicksand,					k_spell_quicksand },
	{ k_version_0_raise_ghost,					k_spell_raise_ghost },
	{ k_version_0_raise_skeletons,				k_spell_raise_skeletons },
	{ k_version_0_raise_vampires,				k_spell_raise_vampires },
	{ k_version_0_ranged_protection,			k_spell_mass_blur },
	{ k_version_0_ray_of_suffering,				k_spell_ray_of_suffering },
	{ k_version_0_rebirth,						k_spell_rebirth },
	{ k_version_0_reflexes,						k_spell_reflexes },
	{ k_version_0_regeneration,					k_spell_regeneration },
	{ k_version_0_endurance,					k_spell_endurance },
	{ k_version_0_resurrection,					k_spell_resurrection },
	{ k_version_0_rock_growth,					k_spell_rock_growth },
	{ k_version_0_sacred_ground,				k_spell_sacred_ground },
	{ k_version_0_sacrifice,					k_spell_sacrifice },
	{ k_version_0_sanctuary,					k_spell_sanctuary },
	{ k_version_0_short_hypnotism,				k_spell_short_hypnotism },
	{ k_version_0_simple_healing,				k_spell_simple_healing },
	{ k_version_0_slayer,						k_spell_slayer },
	{ k_version_0_slow,							k_spell_slow },
	{ k_version_0_smoke,						k_spell_smoke },
	{ k_version_0_snake_strike,					k_spell_snake_strike },
	{ k_version_0_song_of_peace,				k_spell_song_of_peace },
	{ k_version_0_sorrow,						k_spell_sorrow },
	{ k_version_0_speed,						k_spell_speed },
	{ k_version_0_spell_shackle,				k_spell_spell_shackle },
	{ k_version_0_spiritual_fervor,				k_spell_spiritual_fervor },
	{ k_version_0_steal_all_enchantments,		k_spell_steal_all_enchantments },
	{ k_version_0_steal_enchantment,			k_spell_steal_enchantment },
	{ k_version_0_stoneskin,					k_spell_stoneskin },
	{ k_version_0_stone_gaze,					k_spell_stone_gaze },
	{ k_version_0_strength,						k_spell_strength },
	{ k_version_0_stun,							k_spell_stun },
	{ k_version_0_summon_elf,					k_spell_summon_elf },
	{ k_version_0_summon_white_tiger,			k_spell_summon_white_tiger },
	{ k_version_0_summon_air_elemental,			k_spell_summon_air_elemental },
	{ k_version_0_summon_boat,					k_spell_summon_boat },
	{ k_version_0_summon_cerberi,				k_spell_summon_cerberi },
	{ k_version_0_summon_demon,					k_spell_summon_demon },
	{ k_version_0_summon_venom_spawn,			k_spell_summon_venom_spawn },
	{ k_version_0_summon_devils,				k_spell_summon_devils },
	{ k_version_0_summon_earth_elemental,		k_spell_summon_earth_elemental },
	{ k_version_0_summon_faerie_dragon,			k_spell_summon_faerie_dragon },
	{ k_version_0_summon_fire_elemental,		k_spell_summon_fire_elemental },
	{ k_version_0_summon_griffin,				k_spell_summon_griffin },
	{ k_version_0_summon_ice_demon,				k_spell_summon_ice_demon },
	{ k_version_0_summon_imps,					k_spell_summon_imps },
	{ k_version_0_summon_leprechaun,			k_spell_summon_leprechaun },
	{ k_version_0_summon_mantis,				k_spell_summon_mantis },
	{ k_version_0_summon_phoenix,				k_spell_summon_phoenix },
	{ k_version_0_summon_satyr,					k_spell_summon_satyr },
	{ k_version_0_summon_sprite,				k_spell_summon_sprite },
	{ k_version_0_summon_stinkbug,				k_spell_summon_stinkbug },
	{ k_version_0_summon_unicorn,				k_spell_summon_unicorn },
	{ k_version_0_summon_water_elemental,		k_spell_summon_water_elemental },
	{ k_version_0_summon_wolf,					k_spell_summon_wolf },
	{ k_version_0_teleport,						k_spell_teleport },
	{ k_version_0_terrain_walk,					k_spell_terrain_walk },
	{ k_version_0_terror,						k_spell_terror },
	{ k_version_0_town_gate,					k_spell_town_gate },
	{ k_version_0_vampiric_touch,				k_spell_vampiric_touch },
	{ k_version_0_visions,						k_spell_visions },
	{ k_version_0_water_walk,					k_spell_water_walk },
	{ k_version_0_weakness,						k_spell_weakness },
};


enum t_version_1_spells
{
	k_version_1_none = -1,

	k_version_1_acid,
	k_version_1_aging,
	k_version_1_animate_dead,
	k_version_1_anti_magic,
	k_version_1_armageddon,
	k_version_1_banish,
	k_version_1_berserk,
	k_version_1_bind_flyer,
	k_version_1_bind_wound,
	k_version_1_binding,
	k_version_1_bless,
	k_version_1_blind,
	k_version_1_bloodfrenzy,
	k_version_1_bloodlust,
	k_version_1_burning_hands,
	k_version_1_cancellation,
	k_version_1_celestial_armor,
	k_version_1_chain_lightning,
	k_version_1_clone,
	k_version_1_cloud_of_confusion,
	k_version_1_cold_resistance,
	k_version_1_confusion,
	k_version_1_cowardice,
	k_version_1_curse,
	k_version_1_death_call,
	k_version_1_despair,
	k_version_1_disintegrate,
	k_version_1_dispel,
	k_version_1_displacement,
	k_version_1_divine_aura,
	k_version_1_divine_intervention,
	k_version_1_divine_protection,
	k_version_1_divine_retribution,
	k_version_1_dragon_strength,
	k_version_1_evil_hour,
	k_version_1_exorcism,
	k_version_1_fear,
	k_version_1_fear_effect,
	k_version_1_fire_aura_effect,
	k_version_1_fire_bolt,
	k_version_1_fire_resistance,
	k_version_1_fire_ring,
	k_version_1_fire_shield,
	k_version_1_fireball,
	k_version_1_firebreathing,
	k_version_1_first_strike,
	k_version_1_flight,
	k_version_1_forgetfulness,
	k_version_1_fortune,
	k_version_1_freeze,
	k_version_1_gas,
	k_version_1_giant_strength,
	k_version_1_greater_forgetfulness,
	k_version_1_guardian_angel,
	k_version_1_hand_of_death,
	k_version_1_haste,
	k_version_1_heal,
	k_version_1_health_boost,
	k_version_1_holy_armor,
	k_version_1_holy_retribution,
	k_version_1_holy_water,
	k_version_1_holy_word,
	k_version_1_hypnotize,
	k_version_1_ice_bolt,
	k_version_1_illusionary_ally,
	k_version_1_implosion,
	k_version_1_inferno,
	k_version_1_kreegan_fire,
	k_version_1_life_drain,
	k_version_1_lightning,
	k_version_1_luck_boost,
	k_version_1_magic_arrow,
	k_version_1_magic_fist,
	k_version_1_magic_leech,
	k_version_1_magic_mirror,
	k_version_1_magic_resistance,
	k_version_1_mana,
	k_version_1_mana_flare,
	k_version_1_mana_leech,
	k_version_1_martyr,
	k_version_1_mass_bless,
	k_version_1_mass_cancellation,
	k_version_1_mass_curse,
	k_version_1_mass_dispel,
	k_version_1_mass_exorcism,
	k_version_1_mass_first_strike,
	k_version_1_mass_fortune,
	k_version_1_mass_haste,
	k_version_1_mass_healing,
	k_version_1_mass_misfortune,
	k_version_1_mass_precision,
	k_version_1_mass_protection_from_chaos,
	k_version_1_mass_protection_from_death,
	k_version_1_mass_protection_from_nature,
	k_version_1_mass_protection_from_order,
	k_version_1_mass_slayer,
	k_version_1_mass_slow,
	k_version_1_mass_snake_strike,
	k_version_1_mass_sorrow,
	k_version_1_mass_spiritual_fervor,
	k_version_1_mass_weakness,
	k_version_1_mire,
	k_version_1_misfortune,
	k_version_1_morale_boost,
	k_version_1_nature_haste,
	k_version_1_order_slow,
	k_version_1_pain_mirror,
	k_version_1_panic,
	k_version_1_pathfinding,
	k_version_1_physical_protection,
	k_version_1_plague,
	k_version_1_poison,
	k_version_1_poison_attack,
	k_version_1_power_drain,
	k_version_1_prayer,
	k_version_1_precision,
	k_version_1_precognition,
	k_version_1_protection_from_chaos,
	k_version_1_protection_from_death,
	k_version_1_protection_from_life,
	k_version_1_protection_from_nature,
	k_version_1_protection_from_order,
	k_version_1_quickness,
	k_version_1_quicksand,
	k_version_1_raise_ghost,
	k_version_1_raise_skeletons,
	k_version_1_raise_vampires,
	k_version_1_ranged_protection,
	k_version_1_ray_of_suffering,
	k_version_1_rebirth,
	k_version_1_reflexes,
	k_version_1_regeneration,
	k_version_1_endurance,
	k_version_1_resurrection,
	k_version_1_rock_growth,
	k_version_1_sacred_ground,
	k_version_1_sacrifice,
	k_version_1_sanctuary,
	k_version_1_short_hypnotism,
	k_version_1_simple_healing,
	k_version_1_slayer,
	k_version_1_slow,
	k_version_1_smoke,
	k_version_1_snake_strike,
	k_version_1_song_of_peace,
	k_version_1_sorrow,
	k_version_1_speed,
	k_version_1_spell_shackle,
	k_version_1_spiritual_fervor,
	k_version_1_steal_all_enchantments,
	k_version_1_steal_enchantment,
	k_version_1_stoneskin,
	k_version_1_stone_gaze,
	k_version_1_strength,
	k_version_1_stun,
	k_version_1_summon_elf,
	k_version_1_summon_white_tiger,
	k_version_1_summon_air_elemental,
	k_version_1_summon_boat,
	k_version_1_summon_cerberi,
	k_version_1_summon_demon,
	k_version_1_summon_venom_spawn,
	k_version_1_summon_devils,
	k_version_1_summon_earth_elemental,
	k_version_1_summon_faerie_dragon,
	k_version_1_summon_fire_elemental,
	k_version_1_summon_griffin,
	k_version_1_summon_ice_demon,
	k_version_1_summon_imps,
	k_version_1_summon_leprechaun,
	k_version_1_summon_mantis,
	k_version_1_summon_phoenix,
	k_version_1_summon_satyr,
	k_version_1_summon_sprite,
	k_version_1_summon_stinkbug,
	k_version_1_summon_unicorn,
	k_version_1_summon_water_elemental,
	k_version_1_summon_wolf,
	k_version_1_teleport,
	k_version_1_terrain_walk,
	k_version_1_terror,
	k_version_1_town_gate,
	k_version_1_vampiric_touch,
	k_version_1_visions,
	k_version_1_water_walk,
	k_version_1_weakness,

	k_version_1_count = k_version_1_weakness + 1,
};

static int k_version_1_index[][2] =
{
	{ k_version_1_acid,			k_spell_acid },
	{ k_version_1_aging,		k_spell_aging },
	{ k_version_1_animate_dead,	k_spell_animate_dead },
	{ k_version_1_anti_magic,	k_spell_anti_magic },
	{ k_version_1_armageddon,	k_spell_armageddon },
	{ k_version_1_banish,		k_spell_banish },
	{ k_version_1_berserk,		k_spell_berserk },
	{ k_version_1_bind_flyer,	k_spell_bind_flyer },
	{ k_version_1_bind_wound,	k_spell_bind_wound },
	{ k_version_1_binding,		k_spell_binding },
	{ k_version_1_bless,		k_spell_bless },
	{ k_version_1_blind,		k_spell_blind },
	{ k_version_1_bloodfrenzy,	k_spell_bloodfrenzy },
	{ k_version_1_bloodlust,	k_spell_bloodlust },
	{ k_version_1_burning_hands,	k_spell_burning_hands },
	{ k_version_1_cancellation,		k_spell_cancellation },
	{ k_version_1_celestial_armor,	k_spell_celestial_armor },
	{ k_version_1_chain_lightning,	k_spell_chain_lightning },
	{ k_version_1_clone,			k_spell_clone },
	{ k_version_1_cloud_of_confusion,	k_spell_cloud_of_confusion },
	{ k_version_1_cold_resistance,		k_spell_cold_resistance },
	{ k_version_1_confusion,			k_spell_confusion },
	{ k_version_1_cowardice,			k_spell_cowardice },
	{ k_version_1_curse,				k_spell_curse },
	{ k_version_1_death_call,			k_spell_death_call },
	{ k_version_1_despair,				k_spell_despair },
	{ k_version_1_disintegrate,			k_spell_disintegrate },
	{ k_version_1_dispel,				k_spell_dispel },
	{ k_version_1_displacement,			k_spell_displacement },
	{ k_version_1_divine_aura,			k_spell_divine_aura },
	{ k_version_1_divine_intervention,	k_spell_divine_intervention },
	{ k_version_1_divine_protection,	k_spell_divine_protection },
	{ k_version_1_divine_retribution,	k_spell_divine_retribution },
	{ k_version_1_dragon_strength,		k_spell_dragon_strength },
	{ k_version_1_evil_hour,			k_spell_evil_hour },
	{ k_version_1_exorcism,				k_spell_exorcism },
	{ k_version_1_fear,					k_spell_fear },
	{ k_version_1_fire_bolt,			k_spell_fire_bolt },
	{ k_version_1_fire_resistance,		k_spell_fire_resistance },
	{ k_version_1_fire_ring,			k_spell_fire_ring },
	{ k_version_1_fire_shield,			k_spell_fire_shield },
	{ k_version_1_fireball,				k_spell_fireball },
	{ k_version_1_firebreathing,		k_spell_firebreathing },
	{ k_version_1_first_strike,			k_spell_first_strike },
	{ k_version_1_flight,				k_spell_flight },
	{ k_version_1_forgetfulness,		k_spell_forgetfulness },
	{ k_version_1_fortune,				k_spell_fortune },
	{ k_version_1_freeze,				k_spell_freezing_attack },
	{ k_version_1_gas,					k_spell_gas },
	{ k_version_1_giant_strength,		k_spell_giant_strength },
	{ k_version_1_greater_forgetfulness,	k_spell_greater_forgetfulness },
	{ k_version_1_guardian_angel,			k_spell_guardian_angel },
	{ k_version_1_hand_of_death,			k_spell_hand_of_death },
	{ k_version_1_haste,					k_spell_haste },
	{ k_version_1_heal,						k_spell_heal },
	{ k_version_1_health_boost,				k_spell_health_boost },
	{ k_version_1_holy_armor,				k_spell_holy_armor },
	{ k_version_1_holy_retribution,			k_spell_holy_retribution },
	{ k_version_1_holy_water,				k_spell_holy_water },
	{ k_version_1_holy_word,				k_spell_holy_word },
	{ k_version_1_hypnotize,				k_spell_hypnotize },
	{ k_version_1_ice_bolt,					k_spell_ice_bolt },
	{ k_version_1_illusionary_ally,			k_spell_illusionary_ally },
	{ k_version_1_implosion,				k_spell_implosion },
	{ k_version_1_inferno,					k_spell_inferno },
	{ k_version_1_kreegan_fire,				k_spell_kreegan_fire },
	{ k_version_1_life_drain,				k_spell_life_drain },
	{ k_version_1_lightning,				k_spell_lightning },
	{ k_version_1_luck_boost,				k_spell_luck_boost },
	{ k_version_1_magic_arrow,				k_spell_magic_arrow },
	{ k_version_1_magic_fist,				k_spell_magic_fist },
	{ k_version_1_magic_leech,				k_spell_magic_leech },
	{ k_version_1_magic_mirror,				k_spell_magic_mirror },
	{ k_version_1_magic_resistance,			k_spell_magic_resistance },
	{ k_version_1_mana,						k_spell_mana },
	{ k_version_1_mana_flare,				k_spell_mana_flare },
	{ k_version_1_mana_leech,				k_spell_mana_leech },
	{ k_version_1_martyr,					k_spell_martyr },
	{ k_version_1_mass_bless,				k_spell_mass_bless },
	{ k_version_1_mass_cancellation,		k_spell_mass_cancellation },
	{ k_version_1_mass_curse,				k_spell_mass_curse },
	{ k_version_1_mass_dispel,				k_spell_mass_dispel },
	{ k_version_1_mass_exorcism,			k_spell_mass_exorcism },
	{ k_version_1_mass_first_strike,		k_spell_mass_first_strike },
	{ k_version_1_mass_fortune,				k_spell_mass_fortune },
	{ k_version_1_mass_haste,				k_spell_mass_haste },
	{ k_version_1_mass_healing,				k_spell_mass_healing },
	{ k_version_1_mass_misfortune,			k_spell_mass_misfortune },
	{ k_version_1_mass_precision,			k_spell_mass_precision },
	{ k_version_1_mass_protection_from_chaos,	k_spell_mass_protection_from_chaos },
	{ k_version_1_mass_protection_from_death,	k_spell_mass_protection_from_death },
	{ k_version_1_mass_protection_from_nature,	k_spell_mass_protection_from_nature },
	{ k_version_1_mass_protection_from_order,	k_spell_mass_protection_from_order },
	{ k_version_1_mass_slayer,					k_spell_mass_slayer },
	{ k_version_1_mass_slow,					k_spell_mass_slow },
	{ k_version_1_mass_snake_strike,			k_spell_mass_snake_strike },
	{ k_version_1_mass_sorrow,					k_spell_mass_sorrow },
	{ k_version_1_mass_spiritual_fervor,		k_spell_mass_spiritual_fervor },
	{ k_version_1_mass_weakness,				k_spell_mass_weakness },
	{ k_version_1_mire,							k_spell_mire },
	{ k_version_1_misfortune,					k_spell_misfortune },
	{ k_version_1_morale_boost,					k_spell_morale_boost },
	{ k_version_1_nature_haste,					k_spell_nature_haste },
	{ k_version_1_order_slow,					k_spell_order_slow },
	{ k_version_1_pain_mirror,					k_spell_pain_mirror },
	{ k_version_1_panic,						k_spell_panic },
	{ k_version_1_pathfinding,					k_spell_pathfinding },
	{ k_version_1_physical_protection,			k_spell_blur },
	{ k_version_1_plague,						k_spell_plague },
	{ k_version_1_poison,						k_spell_poison },
	{ k_version_1_poison_attack,				k_spell_poison_attack },
	{ k_version_1_power_drain,					k_spell_power_drain },
	{ k_version_1_prayer,						k_spell_prayer },
	{ k_version_1_precision,					k_spell_precision },
	{ k_version_1_precognition,					k_spell_immortality },
	{ k_version_1_protection_from_chaos,		k_spell_protection_from_chaos },
	{ k_version_1_protection_from_death,		k_spell_protection_from_death },
	{ k_version_1_protection_from_life,			k_spell_protection_from_life },
	{ k_version_1_protection_from_nature,		k_spell_protection_from_nature },
	{ k_version_1_protection_from_order,		k_spell_protection_from_order },
	{ k_version_1_quickness,					k_spell_quickness },
	{ k_version_1_quicksand,					k_spell_quicksand },
	{ k_version_1_raise_ghost,					k_spell_raise_ghost },
	{ k_version_1_raise_skeletons,				k_spell_raise_skeletons },
	{ k_version_1_raise_vampires,				k_spell_raise_vampires },
	{ k_version_1_ranged_protection,			k_spell_mass_blur },
	{ k_version_1_ray_of_suffering,				k_spell_ray_of_suffering },
	{ k_version_1_rebirth,						k_spell_rebirth },
	{ k_version_1_reflexes,						k_spell_reflexes },
	{ k_version_1_regeneration,					k_spell_regeneration },
	{ k_version_1_endurance,					k_spell_endurance },
	{ k_version_1_resurrection,					k_spell_resurrection },
	{ k_version_1_rock_growth,					k_spell_rock_growth },
	{ k_version_1_sacred_ground,				k_spell_sacred_ground },
	{ k_version_1_sacrifice,					k_spell_sacrifice },
	{ k_version_1_sanctuary,					k_spell_sanctuary },
	{ k_version_1_short_hypnotism,				k_spell_short_hypnotism },
	{ k_version_1_simple_healing,				k_spell_simple_healing },
	{ k_version_1_slayer,						k_spell_slayer },
	{ k_version_1_slow,							k_spell_slow },
	{ k_version_1_smoke,						k_spell_smoke },
	{ k_version_1_snake_strike,					k_spell_snake_strike },
	{ k_version_1_song_of_peace,				k_spell_song_of_peace },
	{ k_version_1_sorrow,						k_spell_sorrow },
	{ k_version_1_speed,						k_spell_speed },
	{ k_version_1_spell_shackle,				k_spell_spell_shackle },
	{ k_version_1_spiritual_fervor,				k_spell_spiritual_fervor },
	{ k_version_1_steal_all_enchantments,		k_spell_steal_all_enchantments },
	{ k_version_1_steal_enchantment,			k_spell_steal_enchantment },
	{ k_version_1_stoneskin,					k_spell_stoneskin },
	{ k_version_1_stone_gaze,					k_spell_stone_gaze },
	{ k_version_1_strength,						k_spell_strength },
	{ k_version_1_stun,							k_spell_stun },
	{ k_version_1_summon_elf,					k_spell_summon_elf },
	{ k_version_1_summon_white_tiger,			k_spell_summon_white_tiger },
	{ k_version_1_summon_air_elemental,			k_spell_summon_air_elemental },
	{ k_version_1_summon_boat,					k_spell_summon_boat },
	{ k_version_1_summon_cerberi,				k_spell_summon_cerberi },
	{ k_version_1_summon_demon,					k_spell_summon_demon },
	{ k_version_1_summon_venom_spawn,			k_spell_summon_venom_spawn },
	{ k_version_1_summon_devils,				k_spell_summon_devils },
	{ k_version_1_summon_earth_elemental,		k_spell_summon_earth_elemental },
	{ k_version_1_summon_faerie_dragon,			k_spell_summon_faerie_dragon },
	{ k_version_1_summon_fire_elemental,		k_spell_summon_fire_elemental },
	{ k_version_1_summon_griffin,				k_spell_summon_griffin },
	{ k_version_1_summon_ice_demon,				k_spell_summon_ice_demon },
	{ k_version_1_summon_imps,					k_spell_summon_imps },
	{ k_version_1_summon_leprechaun,			k_spell_summon_leprechaun },
	{ k_version_1_summon_mantis,				k_spell_summon_mantis },
	{ k_version_1_summon_phoenix,				k_spell_summon_phoenix },
	{ k_version_1_summon_satyr,					k_spell_summon_satyr },
	{ k_version_1_summon_sprite,				k_spell_summon_sprite },
	{ k_version_1_summon_stinkbug,				k_spell_summon_stinkbug },
	{ k_version_1_summon_unicorn,				k_spell_summon_unicorn },
	{ k_version_1_summon_water_elemental,		k_spell_summon_water_elemental },
	{ k_version_1_summon_wolf,					k_spell_summon_wolf },
	{ k_version_1_teleport,						k_spell_teleport },
	{ k_version_1_terrain_walk,					k_spell_terrain_walk },
	{ k_version_1_terror,						k_spell_terror },
	{ k_version_1_town_gate,					k_spell_town_gate },
	{ k_version_1_vampiric_touch,				k_spell_vampiric_touch },
	{ k_version_1_visions,						k_spell_visions },
	{ k_version_1_water_walk,					k_spell_water_walk },
	{ k_version_1_weakness,						k_spell_weakness },
};

// ------------------------------------------------------------
// read
// ------------------------------------------------------------
bool read_version( std::streambuf& stream, t_spell_set& spell_set, int version )
{
	spell_set.reset();
	if (version == 0)
	{
		std::bitset<k_version_0_count> old_bitset;
		int							   i;

		old_bitset = get_bitset<k_version_0_count>( stream );
		for (i = 0; i < ELEMENTS_OF( k_version_0_index ); i++)
		{
			if (old_bitset[k_version_0_index[i][0]])
				spell_set.set( k_version_0_index[i][1] );
		}
		return true;
	}
	if (version == 1)
	{
		std::bitset<k_version_1_count> old_bitset;
		int							   i;

		old_bitset = get_bitset<k_version_1_count>( stream );
		for (i = 0; i < ELEMENTS_OF( k_version_1_index ); i++)
		{
			if (old_bitset[k_version_1_index[i][0]])
				spell_set.set( k_version_1_index[i][1] );
		}
		return true;
	}
	spell_set = get_bitset<k_spell_count>( stream );
	return true;
}

// ------------------------------------------------------------
// read
// ------------------------------------------------------------
bool read( std::streambuf& stream, t_spell_set& spell_set )
{
	t_uint8 version = get<t_uint8>(stream);

	return read_version( stream, spell_set, version );
	return true;
}

// ------------------------------------------------------------
// write
// ------------------------------------------------------------
bool write( std::streambuf& stream, t_spell_set const& spell_set )
{
	put<t_uint8>( stream, 2 );
	put_bitset< k_spell_count >( stream, spell_set );
	return true;
}
